<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Jerry.DroidBuilder.Controls">

  <local:LevelToIndentConverter x:Key="LevelToIndentConverter"/>

  <!--<LinearGradientBrush x:Key="GridViewColumnHeaderBackground" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#FFFFFFFF" Offset="0"/>
    <GradientStop Color="#FFFFFFFF" Offset="0.4091"/>
    <GradientStop Color="#FFF7F8F9" Offset="1"/>
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="GridViewColumnHeaderBorderBackground" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#FFF2F2F2" Offset="0"/>
    <GradientStop Color="#FFD5D5D5" Offset="1"/>
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="GridViewColumnHeaderHoverBackground" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#FFBDEDFF" Offset="0"/>
    <GradientStop Color="#FFB7E7FB" Offset="1"/>
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="GridViewColumnHeaderPressBackground" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#FF8DD6F7" Offset="0"/>
    <GradientStop Color="#FF8AD1F5" Offset="1"/>
  </LinearGradientBrush>-->
  <Style x:Key="GridViewColumnHeaderGripper" TargetType="{x:Type Thumb}">
    <Setter Property="Canvas.Right" Value="-9"/>
    <Setter Property="Width" Value="18"/>
    <Setter Property="Height" Value="{Binding ActualHeight, RelativeSource={RelativeSource TemplatedParent}}"/>
    <Setter Property="Padding" Value="0"/>
    <!--<Setter Property="Background" Value="{StaticResource GridViewColumnHeaderBorderBackground}"/>-->
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Thumb}">
          <Border Background="Transparent" Padding="{TemplateBinding Padding}">
            <Rectangle Fill="{TemplateBinding Background}" HorizontalAlignment="Center" Width="1"/>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
  <Style TargetType="{x:Type GridViewColumnHeader}">
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <!--<Setter Property="Background" Value="{StaticResource GridViewColumnHeaderBackground}"/>-->
    <!--<Setter Property="BorderBrush" Value="{StaticResource GridViewColumnHeaderBorderBackground}"/>-->
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Padding" Value="2,0,2,0"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
          <Grid SnapsToDevicePixels="true">
            <Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1" Background="{TemplateBinding Background}">
              <Grid>
                <Grid.RowDefinitions>
                  <RowDefinition MaxHeight="7"/>
                  <RowDefinition/>
                </Grid.RowDefinitions>
                <Rectangle x:Name="UpperHighlight" Fill="#FFE3F7FF" Visibility="Collapsed"/>
                <Border Padding="{TemplateBinding Padding}" Grid.RowSpan="2">
                  <ContentPresenter x:Name="HeaderContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0,0,0,1" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </Border>
              </Grid>
            </Border>
            <Border x:Name="HeaderHoverBorder" BorderThickness="1,0,1,1" Margin="1,1,0,0"/>
            <Border x:Name="HeaderPressBorder" BorderThickness="1,1,1,0" Margin="1,0,0,1"/>
            <Canvas>
              <Thumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/>
            </Canvas>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
              <!--<Setter Property="Background" TargetName="HeaderBorder" Value="{StaticResource GridViewColumnHeaderHoverBackground}"/>-->
              <Setter Property="BorderBrush" TargetName="HeaderHoverBorder" Value="#FF88CBEB"/>
              <Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/>
              <Setter Property="Background" TargetName="PART_HeaderGripper" Value="Transparent"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
              <!--<Setter Property="Background" TargetName="HeaderBorder" Value="{StaticResource GridViewColumnHeaderPressBackground}"/>-->
              <Setter Property="BorderBrush" TargetName="HeaderHoverBorder" Value="#FF95DAF9"/>
              <Setter Property="BorderBrush" TargetName="HeaderPressBorder" Value="#FF7A9EB1"/>
              <Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/>
              <Setter Property="Fill" TargetName="UpperHighlight" Value="#FFBCE4F9"/>
              <Setter Property="Visibility" TargetName="PART_HeaderGripper" Value="Hidden"/>
              <Setter Property="Margin" TargetName="HeaderContent" Value="1,1,0,0"/>
            </Trigger>
            <Trigger Property="Height" Value="Auto">
              <Setter Property="MinHeight" Value="20"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="Role" Value="Floating">
        <Setter Property="Opacity" Value="0.4082"/>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
              <Canvas x:Name="PART_FloatingHeaderCanvas">
                <Rectangle Fill="#FF000000" Height="{TemplateBinding ActualHeight}" Opacity="0.4697" Width="{TemplateBinding ActualWidth}"/>
              </Canvas>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Trigger>
      <Trigger Property="Role" Value="Padding">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
              <Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1" Background="{TemplateBinding Background}"/>
              <ControlTemplate.Triggers>
                <Trigger Property="Height" Value="Auto">
                  <Setter Property="MinHeight" Value="20"/>
                </Trigger>
              </ControlTemplate.Triggers>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Trigger>
    </Style.Triggers>
  </Style>

  <Style TargetType="{x:Type local:TreeListViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
    <!--<Setter Property="Background" Value="#00FFFFFF"/>-->
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorLevel=1, Mode=FindAncestor, AncestorType=ItemsControl}}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorLevel=1, Mode=FindAncestor, AncestorType=ItemsControl}}"/>
    <Setter Property="Padding" Value="0,0,0,0"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <!--<Setter Property="Foreground" Value="#FFF0F0F0"/>-->
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="local:TreeListViewItem">
          <!--<StackPanel>
            <Border x:Name="Bd" Height="20" SnapsToDevicePixels="True" Padding="{TemplateBinding Padding}">
              <local:TreeGridViewRowPresenter
                x:Name="PART_Header"
                FirstColumnIndent="{Binding Level, Converter={StaticResource LevelToIndentConverter}, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListViewItem}}, ConverterParameter=10}"
                Content="{TemplateBinding Header}" 
                Columns="{Binding Path=Columns, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListView}}}">
                <local:TreeGridViewRowPresenter.Expander>
                  <Grid Height="20">
                    <ToggleButton x:Name="Expander" VerticalAlignment="Center" ClickMode="Press" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListViewItem}}}" Style="{StaticResource ToggleButtonStyle}"/>
                  </Grid>
                </local:TreeGridViewRowPresenter.Expander>
              </local:TreeGridViewRowPresenter>
            </Border>
            <ItemsPresenter x:Name="ItemsHost" />
          </StackPanel>-->
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition/>
            </Grid.RowDefinitions>
            <Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" Margin="1,0,3,1" CornerRadius="2,2,2,2"/>
            <Grid SnapsToDevicePixels="True">
              <local:TreeGridViewRowPresenter
                x:Name="PART_Header"
                FirstColumnIndent="{Binding Level, Converter={StaticResource LevelToIndentConverter}, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListViewItem}}, ConverterParameter=10}"
                Content="{TemplateBinding Header}" 
                Columns="{Binding Path=Columns, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListView}}}">
                <local:TreeGridViewRowPresenter.Expander>
                  <Grid Height="20">
                    <ToggleButton x:Name="Expander" VerticalAlignment="Center" ClickMode="Press" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListViewItem}}}" Style="{StaticResource TreeViewItemExpander}"/>
                  </Grid>
                </local:TreeGridViewRowPresenter.Expander>
              </local:TreeGridViewRowPresenter>
            </Grid>
            <ItemsPresenter x:Name="ItemsHost" Grid.Row="1"/>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsExpanded" Value="False">
              <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="HasItems" Value="False">
              <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
            </Trigger>
            <!--<Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Bd" Property="Background" Value="#CCFFCC" />
            </Trigger>-->
            <Trigger Property="IsSelected" Value="True">
              <Setter Property="Foreground" Value="#FF333333"/>
              <Setter Property="Background" TargetName="Bd">
                <Setter.Value>
                  <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="#FFE2E2E2" Offset="0"/>
                    <GradientStop Color="#FF9C9C9C" Offset="1"/>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ScrollViewerStyle" TargetType="{x:Type ScrollViewer}">
    <Setter Property="Focusable" Value="False"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollViewer}">
          <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <DockPanel Margin="{TemplateBinding Padding}">
              <!--<ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Focusable="False">
                <GridViewHeaderRowPresenter Columns="{Binding Path=Columns, RelativeSource={RelativeSource AncestorType={x:Type local:TreeListView}}}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
              </ScrollViewer>-->
              <ScrollContentPresenter
                x:Name="PART_ScrollContentPresenter"
                KeyboardNavigation.DirectionalNavigation="Local"
                Content="{TemplateBinding Content}"
                ContentTemplate="{TemplateBinding ContentTemplate}"
                CanContentScroll="{TemplateBinding CanContentScroll}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            </DockPanel>
            <ScrollBar
              x:Name="PART_HorizontalScrollBar"
              Orientation="Horizontal"
              Grid.Row="1"
              Minimum="0.0"
              Maximum="{TemplateBinding ScrollableWidth}"
              ViewportSize="{TemplateBinding ViewportWidth}"
              Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
              Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
              Cursor="Arrow"/>
            <ScrollBar
              x:Name="PART_VerticalScrollBar"
              Orientation="Vertical"
              Grid.Column="1"
              Minimum="0.0"
              Maximum="{TemplateBinding ScrollableHeight}"
              ViewportSize="{TemplateBinding ViewportHeight}"
              Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
              Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
              Cursor="Arrow"/>
            <DockPanel
              Grid.Row="1"
              Grid.Column="1"
              Background="{Binding Path=Background, ElementName=PART_VerticalScrollBar}"
              LastChildFill="False">
              <Rectangle
                DockPanel.Dock="Left"
                Width="1"
                Fill="White"
                Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
              <Rectangle
                DockPanel.Dock="Top"
                Height="1"
                Fill="White"
                Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
            </DockPanel>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:TreeListView}" BasedOn="{StaticResource {x:Type TreeView}}">
    <!--<Setter Property="Background" Value="#00FFFFFF"/>
    <Setter Property="BorderBrush" Value="#00FFFFFF"/>
    <Setter Property="BorderThickness" Value="0,0,0,0"/>
    <Setter Property="Foreground" Value="#FFF0F0F0"/>-->
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="local:TreeListView">
          <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
            <ScrollViewer Style="{StaticResource ScrollViewerStyle}"
                          Background="{TemplateBinding Background}"
                          Focusable="False"
                          CanContentScroll="False"
                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                          Padding="{TemplateBinding Padding}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
            </ScrollViewer>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>